//
//  ClassifyViewController.m
//  网络FM
//
//  Created by dengzhicheng on 15/5/21.
//  Copyright (c) 2015年 dengzhicheng.com. All rights reserved.
//

#import "ClassifyViewController.h"
#import "DBSphereView.h"
#import "ClassifyDetailViewController.h"
#import "ClassifyButton.h"


@interface ClassifyViewController ()

@property (nonatomic, retain) DBSphereView *apple;
@property (nonatomic, retain) ClassifyButton *button;

@end

@implementation ClassifyViewController
- (void)dealloc
{
    [_button release];
    [_apple release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)loadView
{
    [super loadView];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self createImageView];
    [self createDBSphereView];
    [self.view setBackgroundColor:[UIColor colorWithRed:255 / 255.0 green:235 / 255.0 blue:205 / 255.0 alpha:1.0f]];
    self.navigationController.navigationBar.translucent = NO;
 
}

// 创建3D旋转视图
- (void)createDBSphereView
{
    self.apple = [[DBSphereView alloc] initWithFrame:CGRectMake(30, self.view.frame.size.height / 4 + (self.view.frame.size.height / 3 * 2 - (self.view.frame.size.width - 60)) / 3, self.view.frame.size.width - 60, self.view.frame.size.width - 60)];
    // 创建存放按钮的数组
    NSMutableArray *buttonArray = [NSMutableArray array];
    
    //
    NSMutableArray *strArray = [NSMutableArray arrayWithObjects:@"音乐?cate=%E9%9F%B3%E4%B9%90%2F%E6%98%8E%E6%98%9F&page=0", @"新闻?cate=%E6%96%B0%E9%97%BB%2F%E8%B5%84%E8%AE%AF&page=0", @"故事?cate=%E6%95%85%E4%BA%8B%2F%E5%B0%8F%E8%AF%B4&page=0", @"体育?cate=%E4%BD%93%E8%82%B2%2F%E8%B5%9B%E4%BA%8B&page=0", @"交通?cate=%E4%BA%A4%E9%80%9A%2F%E5%87%BA%E8%A1%8C&page=0", @"健康?cate=%E4%BA%A4%E9%80%9A%2F%E5%87%BA%E8%A1%8C&page=0", @"外语?cate=%E4%BA%A4%E9%80%9A%2F%E5%87%BA%E8%A1%8C&page=0", @"互动?cate=%E6%9B%B2%E8%89%BA%2F%E6%88%8F%E5%89%A7&page=0", @"曲艺?cate=%E6%9B%B2%E8%89%BA%2F%E6%88%8F%E5%89%A7&page=0", @"情感?cate=%E6%83%85%E6%84%9F%2F%E4%B8%A4%E6%80%A7&page=0", nil];
    
    NSMutableArray *nameArray = [NSMutableArray array];
    for (int i = 0; i < 5; i++) {
        [nameArray addObject:strArray];
    }
    
    for (NSArray *arr in nameArray) {
        
        for (NSString *str in arr) {
            
            // 以"?"为分隔,截取字符串,并放到数组里
            NSArray *array1 = [str componentsSeparatedByString:@"?"];
            self.button = [[ClassifyButton alloc] initWithFrame:CGRectMake(0, 0, 80, 30)];
            [_button setTitle:[array1 firstObject] forState:UIControlStateNormal];

            // 获取button的字符串属性
            _button.cateStr = [array1 lastObject];;
            
            [_button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
            [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
            _button.titleLabel.font = [UIFont systemFontOfSize:24.0];
            [buttonArray addObject:_button];
            [self.apple addSubview:_button];
        }
    }
    
    [self.apple setCloudTags:buttonArray];
    [self.view addSubview:self.apple];
    

}

// 设置按钮点击事件
- (void)buttonAction:(ClassifyButton *)button
{
//    [self.apple timerStop];
    [UIView animateWithDuration:0.4 animations:^{
        
        button.transform = CGAffineTransformMakeScale(2.0, 2.0);
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.4 animations:^{
            button.transform = CGAffineTransformMakeScale(1.0, 1.0);
        }];
    }];
    
    ClassifyDetailViewController *detail = [[ClassifyDetailViewController alloc] init];
    // 将button的字符串属性传给详细界面
    detail.classify = button.cateStr;
    
    [self.navigationController pushViewController:detail animated:YES];
    [detail release];
    
    
}


// 添加图片
- (void)createImageView
{
    UIImageView *classifyImage= [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 4)];
    [classifyImage setImage:[UIImage imageNamed:@"分类界面图片.png"]];
    [self.view addSubview:classifyImage];
    [classifyImage release];
    

}




@end
